const NodeCache = require("node-cache");
const cache = new NodeCache();

function getDataFromCache(key) {
  const data = cache.get(key);
  if (data) {
    console.log("Fetching data from cache for key:", key);
    return data;
  }
  return null;
}

function setDataToCache(key, data) {
  console.log("Setting data to cache for key:", key, data);
  cache.set(key, data);
}

function deleteDataToCache(key) {
  console.log("delete data to cache for key:", key);
  cache.del(key);
}

function getCacheList() {
  return cache.keys();
}

function hasCacheKey(key) {
  return cache.has(key);
}

module.exports = {
  getDataFromCache,
  setDataToCache,
  deleteDataToCache,
  getCacheList,
  hasCacheKey,
};
